public class JDBC_PrepareStatement {

    @Test
    public void query(){
        //1.获取Connection对象
        Connection con = JDBCUtil.getConnection();

        //2.编写SQL   带？
        String sql = "select * from emp where name = ? and gender= ?";

        //3.获取PrepareStatement对象
        PreparedStatement pst = null;
        ResultSet rs = null;
        try {
            pst = con.prepareStatement(sql);
            //4.给pst 中的sql中的？号设置值
            pst.setString(1,"李兵兵");
            pst.setString(2,"男");

            //5.执行sql语句
            rs = pst.executeQuery();

            //6.遍历结果集
            while(rs.next()){
                /*id INT PRIMARY KEY AUTO_INCREMENT,
                        NAME VARCHAR(10),
                        gender CHAR(1), -- 性别
                salary DOUBLE, -- 工资
                bonus DOUBLE, -- 奖金
                join_date DATE -- 入职日期*/
                int id = rs.getInt("id");
                String name = rs.getString("name");
                String gender = rs.getString("gender");
                double salary = rs.getDouble("salary");
                double bonus = rs.getDouble("bonus");
                Date join_date = rs.getDate("join_date");
                Emp emp = new Emp(id, name, gender, salary, bonus, join_date);
                System.out.println(emp);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        //7.释放资源
        JDBCUtil.close(rs,pst,con);
    }
}